package rotate48;

public class Rotate {

    public void rotate(int[][] matrix) {
        //核心思路就是两次翻转，第一次是按对角线两侧进行翻转。之后是按照水平中间位置进行翻转

        //先翻转按对角线
        int n = matrix.length;
        for (int i = 0; i <n-1 ; i++) {
            for (int j = i+1; j <n ; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }

        //根据x轴中间位置进行翻转
        int mid = n/2;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < mid; j++) {
                int temp=matrix[i][j];
                matrix[i][j] = matrix[i][n - 1 - j];
                matrix[i][n - 1 - j] = temp;
            }
        }


    }

}
